#!/bin/bash
# ssh连接到 小可怜 上

set -e

server_address="okmobile@xkl.okappworld123.tk"

# 上传 mobileprovision文件
# mp_path="$HOME/Desktop/upload.mobileprovision"
server_dst_path="~/tmp/tmp_mp"
if [[ $1 ]]; then
    # 上传 命令行参数里的单个文件
    mp_path="$1" 
    echo -e "upload file: '${mp_path}' to '${server_dst_path}'\n"
    scp "${mp_path}" "${server_address}:${server_dst_path}"
else
    # 上传 local_source_path目录里的所有mobileprovision文件
    # local_source_path="${HOME}/Desktop/uploadMPFile"
    local_source_path="${HOME}/tmp/tmp_mp"
    find "${local_source_path}" -maxdepth 1 -name "*.mobileprovision" -type f -print |
    while read tmp_mp_path
    do
        echo -e "upload file: '${tmp_mp_path}' to '${server_dst_path}'\n"
        scp "${tmp_mp_path}" "${server_address}:${server_dst_path}"
    done
fi

# 在远程服务器上执行sync_mp.py
echo "remote run sync_mp.py"
ssh "${server_address}" << eeooff
source ~/.zshrc
syncmobileprovision -D --path ~/tmp/tmp_mp
exit
eeooff

echo -e "\n*** 导入mobileprovision完成👍***\n"

set +e